<?php

require_once 'PHPUnit/Framework.php';

CCore::Using('mime.emails');

/**
 * Test class for CCoreMimeEmail.
 */
class CCoreMimeEmailTest extends PHPUnit_Framework_TestCase
{
	/**
	 * @var CCoreMimeEmail
	 */
	protected $object;

	/**
	 * This method is called before a test is executed.
	 */
	protected function setUp()
	{
		$this->object = new CCoreMimeEmail('admin@example.com', 'Administrator', 'Remark');
	}

	public function testEmailDisplayNameRemarks()
	{
		$this->assertEquals('admin@example.com', $this->object->Email());
		$this->assertEquals('Administrator', $this->object->DisplayName());
		$this->assertEquals('Remark', $this->object->Remarks());
	}

	public function testGetAccountName()
	{
		$this->assertEquals('admin', $this->object->GetAccountName());
	}

	public function testGetDomain()
	{
		$this->assertEquals('example.com', $this->object->GetDomain());
	}

	public function testToString()
	{
		$this->assertEquals('"Administrator" <admin@example.com> (Remark)', $this->object->ToString());
	}

	public function testParse0()
	{
		$this->assertFalse($this->object->Parse(''));
	}

	public function testParse1()
	{
		$this->assertFalse($this->object->Parse('"Test"'));
	}

	public function testParse2()
	{
		$this->assertTrue($this->object->Parse('"New \" Admin" <help@example.com> (Rem)'));
		$this->assertEquals('help@example.com', $this->object->Email());
		$this->assertEquals('New " Admin', $this->object->DisplayName());
		$this->assertEquals('Rem', $this->object->Remarks());
		$this->assertEquals('help', $this->object->GetAccountName());
		$this->assertEquals('example.com', $this->object->GetDomain());
		$this->assertEquals('"New \" Admin" <help@example.com> (Rem)', $this->object->ToString());
	}

	public function testParse3()
	{
		$this->assertTrue($this->object->Parse('test <help@example.com>'));
		$this->assertEquals('help@example.com', $this->object->Email());
		$this->assertEquals('test', $this->object->DisplayName());
		$this->assertEquals('', $this->object->Remarks());
		$this->assertEquals('help', $this->object->GetAccountName());
		$this->assertEquals('example.com', $this->object->GetDomain());
		$this->assertEquals('"test" <help@example.com>', $this->object->ToString());
	}
	
	
}
